//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __ELASTOS_MDETECT_H__
#define __ELASTOS_MDETECT_H__

#ifdef MUTEX_DEADLOCK_DETECT

class DzMutex;

EXTERN void MutexDeadLockDetection(DzMutex *pCurMutex);

EXTERN void InsertIntoMutexList(DzMutex *pMutex);

EXTERN _ELASTOS Boolean DetachFromMutexList(DzMutex *pMutex);

EXTERN void InitMutexDetection();

#define MDETECT_DEADLOCK_DETECTION \
    { \
        bool_t bOriginalPreemption = DzDisablePreemption(); \
        MutexDeadLockDetection(this); \
        DzRestorePreemption(bOriginalPreemption); \
    }

/*
#define MDETECT_INSERT_INTO_MUTEX_LIST \
    { \
        bool_t bOriginalPreemption = DzDisablePreemption(); \
        InsertIntoMutexList(this); \
        DzRestorePreemption(bOriginalPreemption); \
    }
*/

#define MDETECT_DETACH_FROM_MUTEX_LIST \
    { \
        bool_t bOriginalPreemption = DzDisablePreemption(); \
        DetachFromMutexList(this); \
        DzRestorePreemption(bOriginalPreemption); \
    }

#define MDETECT_INIT InitMutexDetection();

#else

#define MDETECT_DEADLOCK_DETECTION
#define MDETECT_INSERT_INTO_MUTEX_LIST
#define MDETECT_DETACH_FROM_MUTEX_LIST
#define MDETECT_INIT

#endif //MUTEX_DEADLOCK_DETECT

#endif //__ELASTOS_MDETECT_H__
